let long = (str)=>{
  let numArr = []
  if(str.length == 0){
    return 0
  }
  if(str.length > 0){
    numArr.push(1)
  }
  let obj = {}
  for (let index = 0; index < str.length; index++) {
    str[index]
    if(obj[str[index]]){
      obj[str[index]].push(index)
    }else{
      obj[str[index]] = [index]
    }
  }
  let arr = Object.values(obj)
  let checkArr = arr.filter(item => item.length > 2)
  if(checkArr.length>0){
    checkArr.forEach(item => {
      for (let index = 0; index < item.length; index++) {
        if(item[index+1]){
          let num = item[index+1] - item[index]
          if(item[index+1] - item[index] == 1){
            if(checkArr.length > 1){
              numArr.push(2)
            }else{
              numArr.push(1)
            }
          }else{
            numArr.push(num)
          }
        }
      }
    })
  }else{
    numArr.push(arr.length)
  }
  return numArr.sort().reverse()[0]
}
console.log(long('aabb'))
